﻿using Org.BouncyCastle.Asn1.Cms;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PublicFunction
{
    public class RequestInterface
    {
        private async Task<HttpResponseMessage?> sendPostRequest(string path, string jsonStr)
        {
            using (var client = new HttpClient())
            {
                // 设置请求头
                var content = new StringContent(jsonStr, Encoding.UTF8, "application/json");
                try
                {
                    string url = path;
                    // 发送 POST 请求
                    HttpResponseMessage response = await client.PostAsync(url, content);
                    // 处理响应结果
                    if (response.IsSuccessStatusCode)
                    {
                        return response;
                    }
                    else
                    {
                        throw new HttpRequestException("接口响应异常！msg=" + response.StatusCode);
                    }
                }
                catch (Exception)
                {
                    // MessageBox.Show("远程接口调用失败！msg=" + e.Message);
                }
                return null;
            }
        }
    }
}

